home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0095_Drive Types Unit.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  6KB  |  250 lines

  1.  
  2. {$S-,R-,I-,X+}
  3. unit DrvTypes;
  4. { drive types }
  5.  
  6. interface
  7.  
  8. const
  9.   dtError      = $00; { Bad drive }
  10.   dtFixed      = $01; { Fixed drive }
  11.   dtRemovable  = $02; { Removeable (floppy) drive }
  12.   dtRemote     = $03; { Remote (network) drive }
  13.   dtCDROM      = $04; { MSCDEX V2.00+ driven CD-ROM drive }
  14.   dtDblSpace   = $05; { DoubleSpace compressed drive }
  15.   dtSUBST      = $06; { SUBST'ed drive }
  16.   dtStacker4   = $07; { Stacker 4 compressed drive }
  17.   dtRAM        = $08; { RAM drive }
  18.  
  19. function GetDriveType(Drive : Byte) : Byte;
  20.  
  21. implementation
  22.  
  23. type
  24.  ControlBlk25 = record { control block for INT 25 extended call }
  25.    StartSector : LongInt; { start sector to read }
  26.    Count     : Word;    { number of sectors to read }
  27.    BufferOffs  : Word;    { data buffer offset }
  28.    BufferSeg   : Word;    { data buffer segment }
  29.          end;
  30. const
  31.   checkABforStacker : boolean = False;
  32.  
  33. function checkStacker4( Drive : Byte ) : Boolean; assembler;
  34. { returns True if Drive is Stacker 4 compressed volume, False otherwise.
  35.   This also may return True with previous versions of Stacker - I didn't
  36.   check it. /Bobby Z. 29/11/94 }
  37. var CB   : ControlBlk25;
  38.     Boot : array[1..512] of Byte;
  39. asm
  40.  push ds
  41.  mov al,Drive
  42.  or checkABforStacker,0 { check A: & B: for Stacker volume? }
  43.  jnz @@1
  44.  cmp al,1
  45.  ja @@1
  46.  sub al,al
  47.  jmp @@Q
  48. @@1:
  49.  push ss
  50.  pop ds
  51.  lea bx,CB
  52.  sub ax,ax
  53.  mov word ptr ds:ControlBlk25[bx].StartSector,ax
  54.  mov word ptr ds:ControlBlk25[bx].StartSector[2],ax
  55.  mov word ptr ds:ControlBlk25[bx].Count,1
  56.  lea dx,Boot
  57.  mov word ptr ds:ControlBlk25[bx].BufferOffs,dx
  58.  mov word ptr ds:ControlBlk25[bx].BufferSeg,ds
  59.  mov al,Drive
  60.  sub cx,cx
  61.  dec cx
  62.  mov si,sp
  63.  int 25h
  64.  cli
  65.  mov sp,si
  66.  sti
  67.  pushf
  68.  lea si,Boot
  69.  add si,1F0h  { Stacker signature CD13CD14CD01CD03 should }
  70.  sub al,al  { appear at offset 1F0 of boot sector.      }
  71.  popf
  72.  jc @@Q  { was error reading boot sector - assume    }
  73.     { not Stacker drive                         }
  74.  cmp word ptr ds:[si],13CDh
  75.  jnz @@Q
  76.  cmp word ptr ds:[si][2],14CDh
  77.  jnz @@Q
  78.  cmp word ptr ds:[si][4],01CDh
  79.  jnz @@Q
  80.  cmp word ptr ds:[si][6],03CDh
  81.  jnz @@Q
  82.  mov al,1
  83. @@Q:
  84.  pop ds
  85. end;
  86.  
  87. function GetDriveType; assembler;
  88. { Detects the type of a specified drive. Drive is a drive number, where
  89.   0=default (current) drive, 1=drive A, 2=B, ... This function will return
  90.   one of the dtXXX-constants.
  91.  
  92.   Note: Function will work under DOS version 3.1 or later
  93.  
  94.   THIS CODE IS PUBLIC DOMAIN
  95.  
  96.   Written by Mr. Byte, 12/08/94
  97.   Additions and fixes by Bobby Z., 29/11/94
  98.   RAM drive check code by Janis Smits, 07/12/94 }
  99. asm
  100.  cmp Drive,0
  101.  jne @@1
  102.  mov ah,19h    { get active drive number in al }
  103.  int 21h
  104.  inc al
  105.  mov Drive,al
  106. @@1:
  107.  mov ax,1500h  { check for CD-ROM v2.00+ }
  108.  sub bx,bx
  109.  int 2Fh
  110.  or bx,bx
  111.  jz @@2
  112.  mov ax,150Bh
  113.  sub ch,ch
  114.  mov cl,Drive
  115.  int 2Fh
  116.  cmp bx,0ADADh
  117.  jne @@2
  118.  or ax,ax
  119.  jz @@2
  120.  mov bl,dtCDROM
  121.  jmp @@7
  122. @@2:
  123.  mov ax,4409h     { check for SUBST'ed drive }
  124.  mov bl,Drive
  125.  int 21h
  126.  jc @@9
  127.  test dh,10000000b
  128.  jz @@9
  129.  mov bl,dtSUBST
  130.  jmp @@7
  131. @@9:
  132.  mov ax,4A11h  { check for DoubleSpace drive }
  133.  mov bx,1
  134.  mov dl,Drive
  135.  dec dl
  136.  int 2Fh
  137.  sub cl,cl     { mov cl,False }
  138.  or ax,ax     { is DoubleSpace loaded? }
  139.  jnz @@3
  140.  cmp dl,bl     { if a host drive equal to compressed, then get out... }
  141.  je @@3
  142.  test bl,10000000b { bit 7=1: DL=compressed,BL=host
  143.                                     =0: DL=host,BL=compressed }
  144.  jz @@3       { so avoid host drives, assume host=fixed :) }
  145.  inc dl
  146.  cmp Drive,dl
  147.  jne @@3
  148.  mov bl,dtDblSpace
  149.  jmp @@7
  150. @@3:
  151.  mov ax,4409h     { check for remote drive }
  152.  mov bl,Drive
  153.  int 21h
  154.  jc @@5
  155.  and dx,1000h     { this is correct way to check if drive is remote
  156.           one, Andrew. Your version didn't work...
  157.           /Bobby Z., 29/11/94 }
  158.  jz @@4
  159.  mov bl,dtRemote
  160.  jmp @@7
  161. @@4:
  162.  mov al,Drive     { check for Stacker 4 volume }
  163.  or al,al
  164.  jz @@getDrv
  165.  dec al
  166. @@goStac:
  167.  push ax
  168.  call checkStacker4
  169.  or al,al
  170.  jz @@8
  171.  mov bl,dtStacker4
  172.  jmp @@7
  173. @@8:
  174.  mov ax,4408h     { check for fixed (hard) drive }
  175.  mov bl,Drive
  176.  int 21h
  177.  jc @@5
  178.  or al,al
  179.  jz @@6
  180.  push ds           { check for RAM drive }
  181.  mov ax,ss
  182.  mov ds,ax
  183.  mov si,sp
  184.  sub sp,28h       { allocate 28h bytes on stack }
  185.  mov dx,sp
  186.  mov ax,440Dh     { generic IOCTL }
  187.  mov cx,860h      { get device parameters }
  188.  mov bl,Drive
  189.  int 21h          { RAMDrive and VDISK don't support this command }
  190.  mov sp,si
  191.  pop ds
  192.  mov bl,dtRAM
  193.  jc  @@7
  194.  mov bl,dtFixed
  195.  jmp @@7
  196. @@5:
  197.  sub bl,bl     { mov bl,dtError cuz dtError=0 }
  198.  jmp @@7
  199. @@getDrv:
  200.  mov ah,19h
  201.  int 21h
  202.  jmp @@goStac
  203. @@6:
  204.  mov bl,dtRemovable   { else - removeable media }
  205. @@7:
  206.  mov al,bl
  207. end; { GetDriveType }
  208.  
  209. end.
  210.  
  211. { --------------------- TEST PROGRAM --------------------------}
  212. {$S-,I-,R-,X+}
  213. uses DrvTypes;
  214.  
  215. var C : Char;
  216.  
  217. function FloppyDrives : byte; assembler;
  218. asm
  219.         int 11h
  220.         test al,00000001b
  221.         jz  @@1
  222. {$IFOPT G+}
  223.         shr al,6
  224. {$ELSE}
  225.         mov cl,6
  226.         shr al,cl
  227. {$ENDIF}
  228.         and al,3
  229.         inc al
  230.         retn
  231. @@1:
  232.         xor al,al
  233. end;
  234.  
  235. begin
  236.  WriteLn('Drive Map  Version 1.1  Written by Andrew Eigus and Bobby Z.'#13#10);
  237.  for C := 'A' to 'Z' do
  238.   case GetDriveType(Byte(C)-Byte('A')+1) of
  239.    dtCDROM: WriteLn('Drive ', C, ': is CD-ROM drive');
  240.    dtSUBST: WriteLn('Drive ',C,': is SUBST''ed drive');
  241.    dtRAM: WriteLn('Drive ', C, ': is RAM drive');
  242.    dtRemote: WriteLn('Drive ', C, ': is remote (network) drive');
  243.    dtFixed: WriteLn('Drive ', C, ': is local hard drive');
  244.    dtRemovable:
  245.    if (Byte(C) - Byte('A') + 1) in [1..FloppyDrives] then WriteLn('Drive ',C, ': is removable (floppy) drive');
  246.    dtDblSpace: WriteLn('Drive ', C, ': is DoubleSpace compressed drive');
  247.    dtStacker4: WriteLn('Drive ', C, ': is ','Stacker 4 compressed drive');
  248.    end;
  249. end.
  250.